package com.zhima.controller.admin;

import com.zhima.annotation.MustLogin;
import com.zhima.dto.CreateQuestionDTO;
import com.zhima.dto.ZhimaOjResult;
import com.zhima.service.OjQuestionService;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

/**
 * <p>
 * 操作用户自己的题目，都是需要检查登录的
 * </p>
 *
 * @author zhima
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/question/admin")
@MustLogin
public class OjQuestionAdminController {
    @Autowired
    private OjQuestionService ojQuestionService;

    /**
     * 在指定前缀下创建题目
     *
     * @param createQuestionDTO
     * @param prefix
     * @return
     */
    @PostMapping("/new/{prefix}")
    public ZhimaOjResult createNewQuestion(@PathVariable("prefix") String prefix, @RequestBody CreateQuestionDTO createQuestionDTO) {
        return success(ojQuestionService.createNewQuestion(UserHolder.get(), createQuestionDTO, prefix));
    }
}
